// Add for create record begin
function checkPositiveInt(obj){
	var re =/^[1-9]+[0-9]*$/;
	var val = obj.value; 
	if (!isNull(val) && val!=""){
		if(!re.test(val)){
			return false;
		}
	}	
	return true;
}

function checkPositiveNum(obj){
	//var re =/^(([1-9]*[0-9]*.?[0-9]*)|(0[0-9]*.[0-9]*[1-9]+[0-9]*))$/;
	//Revised by Doug
	var re =/^\d+(\.\d+)?$/;
	var val = obj.value; 
	if (!isNull(val) && val!=""){
		if(!re.exec(val)){
			return false;
		}
	}	
	return true;
}

function checkPrice(obj){
	//var re =/^(([1-9]*[0-9]*.?[0-9]*)|(0[0-9]*.[0-9]*[1-9]+[0-9]*))$/;
	var re =/^\d+(\.\d+)?$/;
	var val = obj.value; 
	if (!isNull(val) && val!=""){
		if(!re.test(val)){
			return false;
		}
	}	
	return true;
}

function checkIp(obj){
	var re=/^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/;
	var val = obj.value; 
	if (!isNull(val) && val!=""){
		if(!re.test(val)){
			return false;
		}
	}	
	return true;
}

function checkDate(obj){
	var val = obj.value;
	var re = new RegExp("^(?:(?:([0-9]{4}(-|\/)(?:(?:0?[1,3-9]|1[0-2])(-|\/)(?:29|30)|((?:0?[13578]|1[02])(-|\/)31)))|([0-9]{4}(-|\/)(?:0?[1-9]|1[0-2])(-|\/)(?:0?[1-9]|1\\d|2[0-8]))|(((?:(\\d\\d(?:0[48]|[2468][048]|[13579][26]))|(?:0[48]00|[2468][048]00|[13579][26]00))(-|\/)0?2(-|\/)29))))$");
	if (!isNull(val) && val!=""){
		if(!re.test(val)){
			return false;
		}
	}
	return true;
	
}
// Add for create record end

// Add for fuzzy query date validation begin
function checkFuzzyDate(obj) {
	var val = obj.value;
	var flag = true;
	var re1 = new RegExp("^([1-9][0-9]{3})$");
	var re2 = new RegExp("^[1-9][0-9]{3}(-|\/)(([0][1-9])|([1][0-2]))$");
	var re3 = new RegExp("^(?:(?:([0-9]{4}(-|\/)(?:(?:0?[1,3-9]|1[0-2])(-|\/)(?:29|30)|((?:0?[13578]|1[02])(-|\/)31)))|([0-9]{4}(-|\/)(?:0?[1-9]|1[0-2])(-|\/)(?:0?[1-9]|1\\d|2[0-8]))|(((?:(\\d\\d(?:0[48]|[2468][048]|[13579][26]))|(?:0[48]00|[2468][048]00|[13579][26]00))(-|\/)0?2(-|\/)29))))$");
	if (!isNull(val) && val!=""){
		flag = false;
		if(re1.test(val)){
			flag = true;
		} else if (re2.test(val)){
			flag = true;
		} else if (re3.test(val)){
			flag = true;
		}
	}
	return flag;
}
//Add for fuzzy query date validation end

//Added by Doug for MAC addr verification
function checkMac(obj){
	var val =obj.value;
	var re=/[A-F\d]{2}:[A-F\d]{2}:[A-F\d]{2}:[A-F\d]{2}:[A-F\d]{2}:[A-F\d]{2}/;
	if (!isNull(val) && val!=""){
		if(!re.test(val)){
			return false;
		}
	}
	return true;
}
//Doug's code ends here

//判断是否是数字
function isNumber(str){  
    var re=/^(-|\+)?\d+(\.\d+)?$/;  
    if(!re.test(str)){
    	return false;
    }
    return true;
}
//判断是否是正整数
function checkSignlessNumber(obj_number) {
    var req = /^[1-9]\d*$/;
    var n_value = obj_number.value;
    if(isNull(n_value)){
    	return false;
    }
    var rs = true;
    if (n_value != "") {
        rs = req.test(n_value);
    }
    return rs;
}
//判断金额
function checkMoney($ele) {
    var s = $ele.value;
    if(isNull(s)){
    	alert("the input can not bu null");	
    	return false;
    }
    var index = s.indexOf(".");
    //alert(index);
    if ((index == -1) && s.length > 8) {
        alert("消费数据整数部分最大为8位");
        return false;
    }
    if (index > 8) {
        alert("消费数据整数部分最大为8位");
        return false;
    }
    //if(s.charAt(s.length-1)=="."){
    //	alert('最后一位不能为"."，请重新输入');
    //	return false;
    //}
    //var regu =/^\d+\.{0,1}\d{0,2}$/;
    //判断的格式有：最后一位不为".",最多2位小数，整数超过一位后第一位不为0（零）
    var regu = /^[1-9]+[0-9]*$|^[1-9]+[0-9]*\.\d\d?$|^0\.\d\d?$|^0$/;
    var re = new RegExp(regu);
    var rs = true;
    if (s != "") {
        rs = re.test(s);
    }
    if (!rs)alert("消费数据格式错误：整数最多8位，小数最多2位!");
    return rs;
}
//判断传入的checkbox是否全不选
function checkAllNone(boxArray){
	var isAllNone = true;
	for(var i=0;i<boxArray.length;i++){
		if(boxArray[i].checked){
			isAllNone = false;
			break;
		}
	}
	return isAllNone;
}
//判断是否为空
function checkNull(item) {
    if (isNull(item.value)) {
        return true;
    }
    return false;
}

function isNull($value) {
    if ($value == "" || $value.replace(/\s+/g, "") == "")
        return true;
    return false;
}

//校验图片格式
function checkphototype($file) {
    var str = $file.value;
    strs = str.toLowerCase();
    lens = strs.length;
    extname = strs.substring(lens - 4, lens);
    if (extname != ".jpg" && extname != ".gif")
    {
        alert("图片格式应为jpg/gif，请重新输入");
        return false;
    }
    return true;
}

//去掉左边的空格
function LTrim(str){
    var whitespace = new String(" 　\t\n\r");
    var s = new String(str);
    if (whitespace.indexOf(s.charAt(0)) != -1) {
        var j = 0, i = s.length;
        while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
            j++;
        s = s.substring(j, i);
    }
    return s;
}

//去掉右边的空格
function RTrim(str){
    var whitespace = new String(" 　\t\n\r");
    var s = new String(str);
    if (whitespace.indexOf(s.charAt(s.length - 1)) != -1) {
        var i = s.length - 1;       // Get length of string
        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
            i--;
        s = s.substring(0, i + 1);
    }

    return s;
}

//去掉左右空格
function Trim(str){
    return RTrim(LTrim(str));
}
